package com.tsing.bms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.bms.service.ICarportService;
import com.tsing.bms.vo.req.*;
import com.tsing.bms.vo.resp.CarportRageRespVo;
import com.tsing.bms.vo.resp.CarportRespVo;
import com.tsing.common.annotations.SystemLog;
import com.tsing.common.utils.ResultUtil;
import com.tsing.common.vo.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
@Api(tags = "停车位管理")
@RestController
@RequestMapping("/carport")
public class CarportController {

    @Autowired
    private ICarportService carportService;

    @PostMapping("/addCarport")
    @ApiOperation(value = "新增停车位")
    @SystemLog(description = "新增停车位")
    public ResultData addCarport(@Validated @RequestBody CarportAddReqVo reqVo) {
        carportService.addCarport(reqVo);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteCarport")
    @ApiOperation(value = "删除停车位")
    @SystemLog(description = "删除停车位")
    public ResultData deleteCarport(@Validated @RequestBody IdsReqVo reqVo) {
        carportService.deleteCarport(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/getCarport")
    @ApiOperation(value = "获取单个停车位信息")
    @SystemLog(description = "获取单个停车位信息")
    public ResultData<CarportRespVo> getCarportById(@Validated IdReqVo reqVo) {
        return ResultUtil.success(carportService.getCarport(reqVo));
    }

    @PutMapping("/updateCarport")
    @ApiOperation(value = "修改停车位信息")
    @SystemLog(description = "修改停车位信息")
    public ResultData updateCarport(@Validated @RequestBody CarportUpdateReqVo reqVo) {
        carportService.updateCarport(reqVo);
        return ResultUtil.success();
    }

    @GetMapping("/carportPage")
    @ApiOperation(value = "停车位分页")
    @SystemLog(description = "停车位分页")
    public ResultData<Page<CarportRageRespVo>> carportPage(@Validated CarportPageReqVo reqVo) {
        return ResultUtil.success(carportService.carportPage(reqVo));
    }

}
